public class isPalindrome {
    public boolean isPalindrome(ListNode head) {
        ListNode slow = head;
        ListNode fast = head;
        while(!(fast == null || fast.next == null)){
            slow = slow.next;
            fast = fast.next;
        }
        ListNode prev = null;
        ListNode curr = slow;
        while(curr != null){
            ListNode next = curr.next;
            curr.next = prev;
            prev = curr;
            curr = next;
        }
        ListNode headB = prev;
        ListNode headA = head;
        while(headB != null){
            if(headA.val != headB.val){
                return false;
            }
            headA = headA.next;
            headB = headB.next;
        }
        return true;
    }
}
